package org.tinygame.herostory.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tinygame.herostory.cmdHandler.CmdHandlerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * Redis使用工具类
 * @author shkstart
 * @create 2022-05-08 19:41
 */
public final class RedisUtil {
    /**
     * 日志对象
     */
    private static final Logger LOGGER= LoggerFactory.getLogger(RedisUtil.class);
    /**
     * redis连接池
     */
    private static JedisPool _jedisPool=null;
    /**
     * 私有化默认构造器
     */
    private RedisUtil(){

    }

    public static void init(){
        try{
            _jedisPool=new JedisPool("8.130.26.26",6379);
        }catch (Exception ex){
            LOGGER.error(ex.getMessage(),ex);
        }
    }

    /**
     * 获取redis实例
     * @return
     */
    public static Jedis getRedis(){
        if(null==_jedisPool){
            throw new RuntimeException("_jedisPool尚未初始化");
        }
        Jedis redis= _jedisPool.getResource();
        redis.auth("baijian123456BJS");
        return redis;
    }
}
